﻿<Window x:Class="BingMapsWPFViewer.Views.NewLayerView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Model="clr-namespace:BingMapsWPFViewer.Model;assembly=BingMapsWPFViewer.Model"
        xmlns:vm="http://bingmapswpfviewer.codeplex.com/ViewModel"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:v="clr-namespace:BingMapsWPFViewer.Views"
        xmlns:f="http://bingmapswpfviewer.codeplex.com/Framework"
        Title="New Layer"
        Height="500"
        Width="600"
        Icon="layers.png"
        WindowStartupLocation="CenterOwner"
        f:DialogCloser.DialogResult="{Binding DialogResult}">
    <Window.Resources>
        <v:LayerDataTemplateSelector x:Key="LayerDataTemplateSelector" />

        <vm:LayerTypesViewModel x:Key="LayerTypesViewModel" />

    </Window.Resources>

    <Grid Margin="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- Layer Name -->
        <Grid HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch"
              Grid.Row="0"
              Grid.ColumnSpan="2"
              Background="WhiteSmoke">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="80" />
            </Grid.ColumnDefinitions>
            <TextBlock FontWeight="Bold"
                       Grid.Column="0"
                       Margin="10"
                       VerticalAlignment="Center"
                       FontSize="14">New layer name</TextBlock>
            <TextBox Background="White"
                     Grid.Column="1"
                     HorizontalAlignment="Stretch"
                     Margin="0,10,0,10"
                     FontSize="14"
                     VerticalAlignment="Center"
                     Text="{Binding LayerName, Mode=TwoWay}"></TextBox>
            <Button Content="Generate" Grid.Column="2" Margin="5,0,10,0"
                    Command="{Binding GenerateDisplayNameCommand}"
                    Height="25"></Button>
        </Grid>

        <!-- Layer types -->
        <StackPanel HorizontalAlignment="Stretch"
                    Orientation="Vertical"
                    Grid.Row="1"
                    Margin="5,0,0,0"
                    Grid.Column="0">
            <TextBlock HorizontalAlignment="Left"
                       Text="Layer types"
                       Margin="3"
                       FontWeight="Bold"
                       VerticalAlignment="Center" />
            <ListBox x:Name="lstLayerTypes" HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     Margin="0,5,5,0"
                     ItemsSource="{Binding Source={StaticResource LayerTypesViewModel}, Path=IconView}"
                     BorderThickness="1"
                     BorderBrush="{x:Null}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding ChangeLayerTypeCommand}"
                                               CommandParameter="{Binding ElementName=lstLayerTypes, Path=SelectedItem}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="32" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Image Grid.Column="0"
                                   Width="24"
                                   Height="24"
                                   Source="{Binding Icon}" />
                            <TextBlock Margin="10" Grid.Column="1"
                                   Text="{Binding Name}" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>

        <ContentPresenter Grid.Row="1"
                          Grid.Column="1"
                          Margin="0"
                          Content="{Binding CurrentLayer}"
                          ContentTemplateSelector="{StaticResource LayerDataTemplateSelector}">
            
        </ContentPresenter>
        

        <!-- Buttons -->
        <Button Content="{Binding SaveCaption}"
                Grid.Row="2"
                Grid.ColumnSpan="2"
                Width="100"
                Height="25"
                HorizontalAlignment="Right"
                Margin="0,5,5,5"
                Command="{Binding SaveLayerCommand}"
                IsEnabled="{Binding CurrentLayer.IsValid}"/>
        <Button x:Name="btnClose"
                Content="{Binding CloseCaption}"
                Grid.Row="2"
                Width="100"
                Height="25"
                HorizontalAlignment="Left"
                Command="{Binding CloseCommand}"
                Margin="5,5,0,5"
                IsDefault="True" />

    </Grid>
</Window>
